import { createStore } from "vuex";

const Store = createStore({
  state: {
    storeCount: 0,
    storeName: "zgx",
  },
  mutations: {
    updateCount(state, payload) {
      state.storeCount = payload;
    },
    updateName(state, payload) {
      state.storeName = payload;
    },
  },
  actions: {
    updateCountAsync(context, payload) {
      new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(payload);
        }, 800);
      }).then((res) => {
        context.commit("updateCount", res);
      });
    },
    updateNameAsync(context, payload) {
      new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(payload);
        }, 800);
      }).then((res) => {
        context.commit("updateName", res);
      });
    },
  },
});

export default Store;
